﻿using JWT_Swagger_CoreAPI.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;
using System;
using JWT_Swagger_CoreAPI.Manager.Auth;

namespace JWT_Swagger_CoreAPI.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AuthController : ControllerBase
    {
        private readonly IConfiguration _configuration;
        private readonly IJWTManager _jWTManager;

        public AuthController(IConfiguration configuration,IJWTManager jWTManager)
        {
            _configuration = configuration;
            _jWTManager = jWTManager;
        }

        /// <summary>
        /// 客户端获取Token
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public string Gettoken([FromBody] LoginRequest request)
        {
            if (request.LoginID == "admin" && request.LoginPwd == "1")
            {
                //登录验证之后获取的用户信息
                TokenModelJwt tokenModelJwt = new TokenModelJwt {
                    Role ="1,2,3",
                    Uid =10001,
                    CityID =1
                };


                var jwtToken = _jWTManager.IssueJwt(tokenModelJwt);
                return jwtToken;
            }
            return "密码错误";
        }
    }
}
